import Foundation

let dateFormate = DateFormatter.init()
dateFormate.dateFormat = "yyyyMMdd HH:mm:Z"
let date = dateFormate.string(from: Date()) as String
print("Starting HanMeiMei at \(date)")

repeat {
    let date = dateFormate.string(from: Date()) as String
    let subdate = date.split(separator: " ") as Array<Substring>
    let today = subdate[0] as Substring
    
    workday(day: String(today)) { (needWork) -> (Void) in
        if (needWork) {
            let subTime = subdate[1] as Substring

            let timeSlice = subTime.split(separator: ":") as Array<Substring>

            var hour = Int(timeSlice[0])!
            let minute = Int(timeSlice[1])!

            let zone = Int(String(timeSlice[2]).replacingOccurrences(of: "+", with: ""))
            hour = hour - zone!/100 + 8
            
            // 点餐机器人
            orderFoodNotify(day: String(today), hour: hour, minute: minute)
            // 日报机器人
            weeklyReportJudge(day: String(today), hour: hour, minute: minute)
        }
    }
    
    usleep(29 * 1000 * 1000) //间隔29秒，保证一分钟内触发两次
} while true


